//
//  GQJRunLoopController.m
//  TotalDemo
//
//  Created by gujian on 16/8/4.
//  Copyright © 2016年 gujian. All rights reserved.
//

#import "GQJRunLoopController.h"

@interface GQJRunLoopController()
//@property (nonatomic, strong) NSTimer *timer;

@end

@implementation GQJRunLoopController
{
    NSTimer *timer;
}



- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title = @"runLoop学习";

    [self initRunloop];
    
    [self performSelector:@selector(getFireDate) withObject:nil afterDelay:2.0f];
}

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    [timer invalidate];
    timer = nil;
}

- (void)initRunloop
{
    timer = [NSTimer timerWithTimeInterval:1.0 target:self selector:@selector(logInfo:) userInfo:nil repeats:YES];
    [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
}

- (void)logInfo:(id)info
{
    NSLog(@"timer fired");
}

- (void)getFireDate
{
    
    NSDate *date = [[NSRunLoop currentRunLoop] limitDateForMode:NSDefaultRunLoopMode];
    
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSString *dateStr = [dateFormatter stringFromDate:date];
    
    NSLog(@"dateStr:%@",dateStr);
    
    
}

//- (void)dealloc
//{
//    [timer invalidate];
//    timer = nil;
//}

@end
